package top.likeqc.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import top.likeqc.common.lang.Result;
import top.likeqc.entity.Grade;
import top.likeqc.service.SysUserService;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
public class TestController {
    @Autowired SysUserService userService;

    @Autowired BCryptPasswordEncoder bCryptPasswordEncoder;

    @PreAuthorize("hasRole('admin')")
    @GetMapping("/test")
    public Object test() {
        return Result.success(userService.list());
    }

    @PreAuthorize("hasRole('sys:userr:list')")
    @GetMapping("/test/pass")
    public Object pass() {

        // 加密后的密码
        String password = bCryptPasswordEncoder.encode("111111");

        boolean matches = bCryptPasswordEncoder.matches("111111", password);

        System.out.println("匹配结果：" + matches);

        return Result.success(password);
    }

    /**
     * 模拟 专业信息数据
     * @return
     */
    @GetMapping("/major")
    public Result major() {
        List<String> data = new ArrayList<>();
        data.add("软件工程");
        data.add("计算机与科学技术");
        data.add("网络工程");
        return Result.success(data);
    }

    /**
     * 模拟 学院信息数据
     * @return
     */
    @GetMapping("/college")
    public Result college() {
        List<String> data = new ArrayList<>();
        data.add("数计学院");
        data.add("生化学院");
        data.add("医学院");
        return Result.success(data);
    }

}
